package com.only4play.authcenter.domain.adminaccount;

/**
 * @author hinzzz www.hinzzz.cn 157957329@qq.com
 * 2024-03-05
 */

import com.only4play.authcenter.constants.ThirdPartyAuthType;
import com.only4play.authcenter.infrastructure.constanst.MyConstants;
import com.only4play.authcenter.infrastructure.convert.ThirdPartyAuthTypeConverter;
import com.only4play.codegen.processor.api.*;
import com.only4play.codegen.processor.controller.GenController;
import com.only4play.codegen.processor.creator.GenCreator;
import com.only4play.codegen.processor.creator.IgnoreCreator;
import com.only4play.codegen.processor.mapper.GenMapper;
import com.only4play.codegen.processor.query.GenQuery;
import com.only4play.codegen.processor.repository.GenRepository;
import com.only4play.codegen.processor.service.GenService;
import com.only4play.codegen.processor.service.GenServiceImpl;
import com.only4play.codegen.processor.updater.GenUpdater;
import com.only4play.codegen.processor.updater.IgnoreUpdater;
import com.only4play.codegen.processor.vo.GenVo;
import com.only4play.common.annotation.FieldDesc;
import com.only4play.common.annotation.TypeConverter;
import com.only4play.common.constants.ValidStatus;
import com.only4play.jpa.converter.ValidStatusConverter;
import com.only4play.jpa.support.BaseJpaAggregate;
import lombok.Data;

import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.Table;

@GenVo(pkgName = "com.only4play.authcenter.domain.adminaccount.vo")
@GenCreator(pkgName = "com.only4play.authcenter.domain.adminaccount.creator")
@GenUpdater(pkgName = "com.only4play.authcenter.domain.adminaccount.updater")
@GenRepository(pkgName = "com.only4play.authcenter.domain.adminaccount.repository")
@GenService(pkgName = "com.only4play.authcenter.domain.adminaccount.service")
@GenServiceImpl(pkgName = "com.only4play.authcenter.domain.adminaccount.service")
@GenQuery(pkgName = "com.only4play.authcenter.domain.adminaccount.query")
@GenMapper(pkgName = "com.only4play.authcenter.domain.adminaccount.mapper")
@GenController(pkgName = "com.only4play.authcenter.controller")
@GenCreateRequest(pkgName = "com.only4play.authcenter.api.adminaccount.request", sourcePath = MyConstants.GEN_API_SOURCE)
@GenUpdateRequest(pkgName = "com.only4play.authcenter.api.adminaccount.request", sourcePath = MyConstants.GEN_API_SOURCE)
@GenQueryRequest(pkgName = "com.only4play.authcenter.api.adminaccount.request", sourcePath = MyConstants.GEN_API_SOURCE)
@GenResponse(pkgName = "com.only4play.authcenter.api.adminaccount.response", sourcePath = MyConstants.GEN_API_SOURCE)
@GenFeign(pkgName = "com.only4play.authcenter.api.adminaccount.service", sourcePath = MyConstants.GEN_API_SOURCE, serverName = "auth-srv")
@Entity
@Table(name = "admin_third_party_auth")
@Data
public class AdminThirdPartyAuth extends BaseJpaAggregate {
    @FieldDesc(name = "账号id")
    private Long accountId;

    @FieldDesc(name = "应用id")
    private String applicationId;

    @FieldDesc(name = "认证类型")
    @Convert(converter = ThirdPartyAuthTypeConverter.class)
    @TypeConverter(toTypeFullName = "java.lang.Integer")
    private ThirdPartyAuthType thirdPartyAuthType;

    @FieldDesc(name = "扩展字段")
    private String ext;

    @FieldDesc(name = "认证主体")
    private String principal;

    @FieldDesc(name = "凭证")
    private String credential;

    @Convert(converter = ValidStatusConverter.class)
    @IgnoreUpdater
    @IgnoreCreator
    private ValidStatus validStatus;

    public void init() {
        setValidStatus(ValidStatus.VALID);
    }

    public void valid() {
        setValidStatus(ValidStatus.VALID);
    }

    public void invalid() {
        setValidStatus(ValidStatus.INVALID);
    }
}
